{include file="public/header" /}
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('authRule/index')}">菜单规则</a></li>
        <li class="active"><a href="javascript:;">添加菜单</a></li>
    </ul>
    <form method="post" class="form-horizontal js-ajax-form margin-top-20">
        <table class="table table-bordered">
            <tr>
                <th>所属上级</th>
                <td>
                    <select class="form-control" name="parentId" style="width: 200px;">
                        <option value='0'>默认（顶级）</option>
                        {foreach name="category" item="vo"}
                        <option value='{$vo.id}' {if condition="$vo['id'] eq $info['ac_parent_id']" } selected="selected" {/if} >{$vo.name}</option>
                            {foreach name="$vo['children']" item="vo2"}
                            <option value='{$vo2.id}' {if condition="$vo2['id'] eq $info['ac_parent_id']" } selected="selected" {/if} >└─────{$vo2.name}</option>
                            {/foreach}
                        {/foreach}
                    </select>
                </td>
            </tr>
            <tr>
                <th width="150">菜单名称<span class="form-required">*</span></th>
                <td>
                    <input class="form-control" type="text" name="name" value="" placeholder="请输入菜单名称"/>
                </td>
            </tr>
            <tr>
                <th>控制器</th>
                <td>
                    <input class="form-control" type="text" name="controllerName" value="" placeholder="请输入控制器名称"/>
                </td>
            </tr>
            <tr>
                <th>方法</th>
                <td>
                    <input class="form-control" type="text" name="actionName" value="" placeholder="请输入方法名称"/>
                </td>
            </tr>
            <tr>
                <th>图标</th>
                <td>
                    <label>将对应英文代码复制下来<a href="http://fontawesome.dashgame.com/" target="_blank">传送门</a></label>
                    <input class="form-control" type="text" name="icon" value="" placeholder="请输入对应图标英文代码"/>
                </td>
            </tr>
            <tr>
                <th>状态</th>
                <td>
                    <select class="form-control" name="status" style="width: 200px;">
                        <option value='1' {if condition="$info['status'] eq '1'"}selected="selected" {/if} >启用</option>
                        <option value='0' {if condition="$info['status'] eq '0'"}selected="selected" {/if} >禁用</option>
                    </select>
                </td>
            </tr>
            <tr>
                <th></th>
                <td>
                    <div class="col-sm-offset-2 col-sm-10">
                        <input type="hidden" name="action" value="{$params['action']}" />
                        <button type="button" class="btn btn-primary js-ajax-submit">提交</button>
                        <a class="btn btn-default" href="{:url('authRule/index')}">返回</a>
                    </div>
                </td>
            </tr>
        </table>
    </form>
</div>
<script src="/static/admin/js/layer/layer.js"></script>
<script type="text/javascript">
    $(function () {
        $(".js-ajax-submit").click(function () {
            $.ajax({
                url: "{:url('authRule/operateAjax')}",
                type: "POST",
                data: $(".js-ajax-form").serialize(),
                dataType: 'json',
                async: false,
                success: function (res) {
                    if(res.errorCode === 200){
                        layer.confirm(res.message, {
                            btn:['确认','取消'],
                            success:function(){
                                this.enterEsc = function (event) {
                                    if (event.keyCode === 13) {
                                        $(".layui-layer-btn0").click();
                                        return false;
                                    }
                                };
                                $(document).on('keydown', this.enterEsc);

                                $(".layui-layer-btn0").on("click",function() {
                                    window.location.href = "{:url('authRule/index')}";
                                    return false
                                })
                            },
                            end:function(){
                                $(document).off('keydown',this.enterEsc);
                            }
                        });
                    }else{
                        layer.alert(res.message, {
                            title: '提示',
                            icon: 2
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
